#include <stdio.h>
#include <string.h>
#include "openssl/evp.h"
#include "err.h"

void tDigest(){
        unsigned char md_value[EVP_MAX_MD_SIZE];
        int md_len, i;
        EVP_MD_CTX *mdctx;
        char msg1[] = "20191312";
        char msg2[] = "liuxinyu";
        mdctx = EVP_MD_CTX_new();
        EVP_MD_CTX_init(mdctx);

        EVP_DigestInit_ex(mdctx, EVP_sm3(), NULL);
        EVP_DigestUpdate(mdctx, msg1, strlen(msg1));
        EVP_DigestUpdate(mdctx, msg2, strlen(msg2));
        EVP_DigestFinal_ex(mdctx, md_value, &md_len);
        EVP_MD_CTX_free(mdctx);

        printf("原始数据%s和%s的摘要值为：\n", msg1, msg2);
        for(i = 0; i < md_len; i++){
                printf("0x%02x", md_value[i]);
        }
        printf("\n");
}

int main(){
        OpenSSL_add_all_algorithms();
        tDigest();
        return 0;
}
